package com.bwie.web.controller;


import com.bwie.feginclient.UserFeginClient;
import com.bwie.pojo.Order;
import com.bwie.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/order")
public class OrderFeignController {

    //注入用户feign的客户端(动态代理对象)
    @Autowired
    private UserFeginClient userFeginClient;

    @GetMapping("/feign/{id}")
    public Order listById(@PathVariable String id){

        //模拟从数据库查询出的数据user
        Order order= new Order(id,"小米手机"+id,id,null);

        //远程调用用户微服务
        User user= userFeginClient.findUserByUserId(order.getUserId());

        //取值赋值
        order.setUserName(user.getUsername());
        return order;
    }


}
